package com.homedo.odin.solution.controller.mng;

import com.homedo.core.common.base.controller.BaseController;
import com.homedo.core.common.base.dto.Meta;
import com.homedo.core.common.base.dto.ResultData;
import com.homedo.core.common.exception.BizException;
import com.homedo.core.common.util.NumberHelper;
import com.homedo.odin.solution.contract.mng.CommonDataEditReq;
import com.homedo.odin.solution.contract.mng.CommonTypeDataEditReq;
import com.homedo.odin.solution.contract.mng.CommonTypeDataPageResp;
import com.homedo.odin.solution.contract.mng.CommonTypeDataReq;
import com.homedo.odin.solution.contract.mng.CommonTypeDataResp;
import com.homedo.odin.solution.service.ColumnTagServiceImpl;
import com.homedo.odin.solution.service.bizservice.mng.MngCommonBizService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: zhaoxudong
 * @date: 2018/4/11 14:43
 * @Description:
 */
@Api(description = "公共信息", tags = {"CommonData"}, produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/mng/common_data")
public class MngCommonDataController extends BaseController<MngCommonBizService> {

    @Autowired
    private ColumnTagServiceImpl columnTagService;

    @ApiOperation(value = "OMS_获取基础数据(根据id获取该id的子节点,id为空时获取所有数据",
            notes = "OMS_获取基础数据(根据id获取该id的子节点,id为空时获取所有数据)1:企业类型 ,2业务类型,3专业领域,4服务区域,5一级系统属性,6建筑业态,7行业规范分类,8 品牌分类", response = CommonTypeDataResp.class)
    @GetMapping
    public ResultData nodes(@ApiParam("1:企业类型 ,2业务类型,3专业领域,4服务区域," +
            "5一级系统属性,6建筑业态,7行业规范分类,8 品牌分类") @RequestParam(value = "id", required = false) Integer id) {
        CommonTypeDataResp resp = baseService.nodes(id);
        return ResultData.newInstance(resp);
    }

    @ApiOperation(value = "OMS_修改基础数据", notes = "OMS_修改基础数据")
    @PutMapping
    public ResultData edit(@RequestBody CommonDataEditReq req) {
        baseService.edit(req);
        return ResultData.newInstance();
    }

    @ApiOperation(value = "OMS_新增基础数据", notes = "OMS_新增基础数据")
    @PostMapping
    public ResultData add(@RequestBody CommonTypeDataReq req) {
        baseService.add(req);
        return ResultData.newInstance();
    }

    @ApiOperation(value = "OMS_删除基础数据", notes = "OMS_删除基础数据")
    @DeleteMapping("/{id}")
    public ResultData del(@ApiParam("id") @PathVariable("id") Integer id) {
        baseService.del(id);
        return ResultData.newInstance();

    }

    @ApiOperation(value = "OMS_获取业态和系统高亮词",
            notes = "OMS_获取业态和系统高亮词", response = CommonTypeDataPageResp.class)
    @GetMapping("/highdata")
    public ResultData highData() {
        CommonTypeDataPageResp resp = baseService.highCommonData();
        return ResultData.newInstance(Meta.CODE_200, resp);
    }

    @ApiOperation(value = "OMS_根据id获取业态/系统管理",
            notes = "OMS_根据id获取业态/系统管理", response = CommonTypeDataResp.class, httpMethod = "GET")
    @GetMapping("/{id}/important")
    public ResultData important(@ApiParam("1:企业类型 ,2业务类型,3专业领域,4服务区域," +
            "5一级系统属性,6建筑业态,7行业规范分类,8 品牌分类") @PathVariable(value = "id", required = true) Integer id) {
        if (!NumberHelper.validatePositive(id)) {
            throw new BizException(Meta.CODE_451.getCode(), "参数异常");
        }
        CommonTypeDataResp resp = baseService.important(id);
        return ResultData.newInstance(Meta.CODE_200, resp);
    }

    @ApiOperation(value = "OMS_单个修改传递的基础数据为选中", notes = "OMS_单个修改传递的基础数据为选中")
    @PutMapping("/hightlight")
    public ResultData hightlight(@RequestBody CommonTypeDataEditReq req) {
        if (!NumberHelper.validatePositive(req.getId())) {
            throw new BizException(Meta.CODE_451.getCode(), Meta.CODE_451.getMsg());
        }
        baseService.hightlight(req);
        return ResultData.newInstance(Meta.CODE_200, "修改高亮成功");
    }
}
